package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.dto.DishPageQueryDTO;

import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {
    /**
     * 分页查询菜品信息
     *
     * @param pageQueryDTO
     * @return
     */
    Page<DishVO> dishList(DishPageQueryDTO pageQueryDTO);

    /**
     * 添加菜品
     *
     * @param dish
     */
    void saveDish(Dish dish);

    /**
     * 菜品起售和停售
     *
     * @param status
     * @param id
     */
    @Update("update dish set status = #{status} where id = #{id}")
    void startOrStop(@Param("status") Integer status, @Param("id") Long id);

    /**
     * 查询菜品信息
     *
     * @param id
     * @return
     */
    @Select("  select d.*, c.name as categoryName\n" +
            "        from dish d\n" +
            "                 left join category c on d.category_id = c.id where d.id = #{id}")
    DishVO getDishById(Long id);

    /**
     * 更新菜品信息
     *
     * @param dish
     */
    void updateDishById(Dish dish);

    /**
     * 获取删除的菜品信息
     *
     * @param ids
     * @return
     */
    List<Dish> selectBatchIds(@Param("ids") List<Long> ids);

    /**
     * 删除菜品信息
     *
     * @param ids
     */
    void deleteBatchIds(@Param("ids") List<Long> ids);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    @Select("select * from dish where status=1 and dish.category_id in (#{categoryId})  order by create_time desc;")
    List<Dish> list(Long categoryId);

    /**
     * 查询当前分类是否关联了菜品
     *
     * @param id
     * @return
     */
    @Select("select count(*) from dish where category_id = #{id}")
    long getCountCategoryId(Long id);

    /**
     * 判断菜品是否存在
     *
     * @param name
     * @return
     */
    @Select("select count(*) from dish where name = #{name}")
    long selectCountDishName(String name);

    /**
     * 判断套餐下的菜品是否起售
     *
     * @param longList
     * @return
     */
    long countStatusByIds(@Param("ids") List<Long> longList);

    /**
     * 获取所有菜品信息
     *
     * @return
     */
    @Select("select * from dish where status=1  order by create_time desc;")
    List<Dish> listAllDish();
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
